
package BD;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.SQLException;

public class ConnectionManager {

   private static Connection con;
   private static Statement stmt;

    public static Statement getStmt() {
        return stmt;
    }

    public static void setStmt(Statement stmt) {
        ConnectionManager.stmt = stmt;
    }

   public static void ConnectDB () throws SQLException, ClassNotFoundException
   {
    try {
      Class.forName("com.mysql.jdbc.Driver");
 
      con = DriverManager.getConnection ("jdbc:mysql://localhost:3306/estacionamento?zeroDateTimeBehavior=convertToNull", "root", "root");
      stmt = con.createStatement ();

    }
    catch (SQLException e) {
      System.out.println ( "problemas para abrir database" );
      System.out.println ("Mensagem : " + e.getClass ());
      System.out.println ("Mensagem : " + e.getMessage ());
    }
  }

  // Elimina a conex�o com o banco de dados.
  public static void CloseDB () {
    try {
      stmt.close ();
      con.close ();
    }
    catch (Exception e) {
      System.out.println ( "problemas para fechar database" );
    }
  }
}
